<!-- 工程进度款支付申请 -->
<template>
	<view>
		<u-sticky>
			<u-tabs
				class="tabs" 
				:list="tabsList" 
				@click="onTabClick"
				:scrollable="false" style="padding: 0 24rpx;background: #FFF;z-index:22;position: sticky;top: 0px;"
				:activeStyle="{color:'#171717', fontSize: '14px'}"
				:inactiveStyle="{color:'#C6C6C6', fontSize: '14px'}"
				:itemStyle="{ whiteSpace:'nowrap',height: '44px' }"
				lineColor="#1E6FFF"
			></u-tabs>
		</u-sticky>
		<view class="task_lists" :style="{ paddingBottom: tabvalue == '待办'?'130rpx':'0' }">
			<collapse name="基本信息" id="outside1" :maxHeight="maxHeight1">
				<view class="listdefault" :id="uId1">
					<block v-for="(item,key) in basicInfo1" :key="key">
						<view class="action" >
							<view class="list1">{{ key }}</view>
							<view class="list2">{{ detailData[item] }}</view>
						</view>
					</block>
					<view class="action" >
						<view class="list1">关联项目</view>
						<view class="list2" style="color: #1E6FFF;" @click="onClickProjectName(detailData)">{{ detailData.projectId_dictText }}</view>
					</view>
					<block v-for="(item,key) in basicInfo2" :key="key">
						<view class="action" >
							<view class="list1">{{ key }}</view>
							<view class="list2">{{ detailData[item] }}</view>
						</view>
					</block>
				</view>
			</collapse>
			<collapse name="建设方信息" id="outside2" :maxHeight="maxHeight2">
				<view class="listdefault" :id="uId2">
					<block v-for="(item,key) in ownerInfo" :key="key">
						<view class="action">
							<view class="list1">{{ key }}</view>
							<view class="list2">{{ ownerInfoObj[item] }}</view>
						</view>
					</block>
				</view>
			</collapse>
			<collapse name="施工方信息" id="outside3" :maxHeight="maxHeight3">
				<view class="listdefault" :id="uId3">
					<block v-for="(item,key) in constructInfo" :key="key">
						<view class="action">
							<view class="list1">{{ key }}</view>
							<view class="list2">{{ constructInfoObj[item] }}</view>
						</view>
					</block>
					<block v-if="constructInfoObj.payMode=='1'">
						<view class="action" >
							<view class="list1">开户行</view>
							<view class="list2">{{ constructInfoObj.bankName }}</view>
						</view>
						<view class="action" >
							<view class="list1">账户</view>
							<view class="list2">{{ constructInfoObj.accountNo }}</view>
						</view>
					</block>
					<block >
						<view class="action" >
							<view class="list1">备注</view>
							<view class="list2">{{ constructInfoObj.remark }}</view>
						</view>
					</block>
				</view>
			</collapse>
			<default-list name="附件">
				<file-list :fileList="detailData.attachments"></file-list>
			</default-list>
		</view>
		
		<u-toast ref="uToast"></u-toast>
	</view>
</template>
<script>
	import actionCollapse from '@/pages/synergy/components/actionCollapse.vue'
	import fileList from '@/pages/synergy/components/fileList.vue'
	import collapse from '@/pages/synergy/components/collapse.vue'
	import defaultList from '@/pages/synergy/components/defaultList.vue'
	import {
		queryByIdProjectPayment, // 根据id查询信息
		getProcessHistoryList, // 查询流程图信息
		getProcessHistoryTaskList, // 查询历史流程图信息
		getNodePositionInfo, // 查询坐标信息数据
		rejectProcess, // 退回
		processComplete ,// 提交完成
		getChildrenListOwner,
		getChildrenListParty
	} from '@/api/index.js'
	import {
		BASE_URL
	} from '@/utils/baseUrl.js'
	export default {
		data() {
			return {
				tabsList: [
					{ name: '基本信息',id: 'outside1' },
					{ name: '建设方信息',id: 'outside2' },
					{ name: '施工方信息',id: 'outside3' }
				],
				detailData: {}, // 详情数据
				dictOptions: {}, // 数据字典数据
				basicInfo1: { // 主表信息字段
					'单据编号': 'billNo',
					'申请人': 'proposer_dictText',
					'申请时间': 'createTime',
					'申请部门': 'proposerDeptId_dictText',
				},
				basicInfo2: { // 主表信息字段
					'申请单位': 'applicant_dictText',
					'费用所属团队': 'projectBusiTeamId_dictText',
					'业绩归属年度': 'projectYear',
					'本项目累计支付金额(元)': 'projectPaidTotalAmount',
					'本项目累计支付比例(%)': 'projectPaidRate',
					'是否垫付工程款': 'isAdvance_dictText',
					'采购类别': 'projectPurchaseCategories_dictText',
					'备注': 'remark'
				},
				ownerInfo: {
					'关联收款合同': 'conllectionContractId_dictText',
					'建设单位合同金额(元)': 'ownerContractAmount',
					'建设单位调整后合同金额(元)': 'ownerAdjustedContractAmount',
					'建设单位已回款金额(元)': 'ownerReturnedAmount',
					'建设单位已回款比例(%)': 'ownerReturnedRate',
				}, // 建设方信息字段
				constructInfo: {
					'关联付款合同': 'paymentContractId_dictText',
					'施工方合同金额(元)': 'constructionContractAmount',
					'施工方调整后合同金额(元)': 'constructionAdjustedContractAmount',
					'已开票累计金额(元)': 'invoicedTotalAmount',
					'已支付金额(元)': 'paidAmount',
					'发票类型': 'isSpecialInvoice_dictText',
					'报销金额(元)': 'reimbursementAmount',
					'税费金额(元)': 'taxAmount',
					'未税金额(元)': 'untaxedAmount',
					'本次支付金额(元)': 'currentPaymentAmount',
					'本次支付比例(%)': 'currentPaymentRate',
					'累计支付金额(元)': 'paidTotalAmount',
					'累计支付比例(%)': 'paidTotalRate',
					'付款方式': 'payMode_dictText',
					'收款单位': 'payeeName_dictText',
				}, // 施工方信息字段
				resultList: [], // 流程图数据
				nodePositionInfo: {}, // 坐标信息
				processInstanceId: '',
				scrollTop: 0, // 滚动顶部距离
				model: {}, // 处理单据表信息
				resultObj: {}, // 流程图流转信息
				nodeObj: {}, // 流程节点信息
				tabvalue: '', // 协同首页tabs name
				// childSource: [], // 子表数据
				ownerInfoObj: {},
				constructInfoObj: {},
				isClick: false,
				maxHeight1: 0,
				maxHeight2: 0,
				maxHeight3: 0,
				uId1: uni.$u.guid(),
				uId2: uni.$u.guid(),
				uId3: uni.$u.guid(40),
				id: ''
			}
		},
		components: {
			actionCollapse,
			fileList,
			collapse,
			defaultList
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		onLoad(options) {
			this.id = options.id || ''
			this.loadData(this.id)
		},
		methods: {
			// 查询预立项申请详情
			loadData(id){
				queryByIdProjectPayment({ id }).then(res => {
					if(res.success){
						this.detailData = res.result
						if(res.result.constructInfo.isRelPaymentContract != '1'){
							this.constructInfo = {
								'施工方调整后合同金额(元)': 'constructionAdjustedContractAmount',
								'已开票累计金额(元)': 'invoicedTotalAmount',
								'已支付金额(元)': 'paidAmount',
								'发票类型': 'isSpecialInvoice_dictText',
								'报销金额(元)': 'reimbursementAmount',
								'税费金额(元)': 'taxAmount',
								'未税金额(元)': 'untaxedAmount',
								'本次支付金额(元)': 'currentPaymentAmount',
								'本次支付比例(%)': 'currentPaymentRate',
								'累计支付金额(元)': 'paidTotalAmount',
								'累计支付比例(%)': 'paidTotalRate',
								'付款方式': 'payMode_dictText',
								'收款单位': 'payeeName_dictText',
								'备注': 'remark',
							}
						}
						if(res.result.ownerInfo.isRelConllectionContract != '1'){
							this.ownerInfo = {
								'建设单位调整后合同金额(元)': 'ownerAdjustedContractAmount',
								'建设单位已回款金额(元)': 'ownerReturnedAmount',
								'建设单位已回款比例(%)': 'ownerReturnedRate',
							}
						}
						this.getChildData(res.result.id)
						this.getChildData1(res.result.id)
						this.timer = setTimeout(() =>{
							clearTimeout(this.timer)
							this.timer = null
							this.$nextTick(() => {
								uni.createSelectorQuery().in(this).select('#'+this.uId1).boundingClientRect(data => {
									this.maxHeight1 = data.height
								}).exec();
							})
						}, 300)
					} else {
						this.$refs.uToast.show({
							message: res.message,
							type: 'error'
						})
					}
				})
			},
			// 查询内容高度
			queryRect() {
				// #ifndef APP-NVUE
				// $uGetRect为uView自带的节点查询简化方法，详见文档介绍：https://www.uviewui.com/js/getRect.html
				// 组件内部一般用this.$uGetRect，对外的为uni.$u.getRect，二者功能一致，名称不同
				return new Promise(resolve => {
					this.$uGetRect(`#${this.uId3}`).then(size => {
						resolve(size)
					})
				})
				// #endif
			},
			async getmain(){
				const rect = await this.queryRect()
				this.maxHeight3 = rect.height
			},
			// 查询子表数据
			getChildData(id){
				getChildrenListParty({ billId: id }).then(res => {
					if(res.success){
						this.constructInfoObj = res.result
						this.timer3 = setTimeout(() => {
							clearTimeout(this.timer3)
							this.timer3 = null
							this.$nextTick(function(){
								this.getmain()
							})
						},300)
						
					}
				})
			},
			// 查询子表数据
			getChildData1(id){
				getChildrenListOwner({ billId: id }).then(res => {
					if(res.success){
						this.ownerInfoObj = res.result
						this.timer2 = setTimeout(() => {
							clearTimeout(this.timer2)
							this.timer2 = null
							this.$nextTick(() => {
								uni.createSelectorQuery().in(this).select('#'+this.uId2).boundingClientRect(data => {
									this.maxHeight2 = data.height
								}).exec();
							})
						},300)
						
					}
				})
			},
			// 点击tabs
			onTabClick (item) {
				uni.createSelectorQuery().in(this).select(`#${item.id}`).boundingClientRect(data => {
					uni.pageScrollTo({
						scrollTop:data.top + this.scrollTop - 54,
						duration: 150
					})
				 }).exec();
			},
			// 点击项目名称
			onClickProjectName (item) {
				uni.redirectTo({
					url: '/pages/reportFilesList/erpProjectReportListDetail?id=' + item.projectId
				})
			},
		}
	}
</script>
<style lang="scss" scoped>
@import "@/pages/synergy/common/action.scss";
.task_lists{
	padding: 20rpx 20rpx 0;
}
.image_lists{
	padding: 0 0 12rpx 12rpx;
	display: flex;
	flex-wrap: wrap;
	.image_list{
		margin-bottom: 20rpx;
		width: 144rpx;
		margin-right: 14rpx;
		.image_img{
			width: 116rpx;
			height: 116rpx;
			padding: 12rpx;
			background: rgba(0,0,0,0.0200);
			border-radius: 1px;
			border: 1px solid rgba(0,0,0,0.0800);
			position: relative;
			.image_action{
				position: absolute;
				top: 50%;
				left: 50%;
				transform: translateX(-50%) translateY(-50%);
				width: 36rpx;
				height: 36rpx;
			}
			.image_source{
				width: 100%;
				height: 100%;
			}
		}
		.image_name{
			font-size: 10px;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #B2B2B2;
			line-height: 28rpx;
			margin-top: 8rpx;
			text-align: left;
			overflow:hidden;
			white-space:nowrap;
			text-overflow:ellipsis;
			width: 152rpx;
		}
	}
}

.flow_right{
	display: flex;
	align-items: center;
	image{
		width: 40rpx;
		height: 40rpx;
	}
	text{
		font-size: 14px;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #1E6FFF;
		line-height: 40rpx;
		margin-left: 4rpx;
	}
}

.task_bottom{
	display: flex;
	align-items: center;
	padding: 20rpx 0 20rpx 52rpx;
	background-color: #FFFFFF;
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	z-index: 10000;
	.task_bottom_write{
		display: flex;
		align-items: center;
		image{
			width: 48rpx;
			height: 48rpx;
			margin-right: 8rpx;
		}
		text{
			font-size: 14px;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #7F7F7F;
			line-height: 40rpx;
		}
	}
	.refuse{
		width: 168rpx;
		height: 90rpx;
		line-height: 90rpx;
		background: rgba(0,0,0,0.0500);
		border-radius: 10rpx;
		margin: 0 16rpx 0 52rpx;
		font-size: 17px;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: rgba(0,0,0,0.5000);
		text-align: center;
	}
	.agree{
		width: 318rpx;
		height: 90rpx;
		line-height: 90rpx;
		background: #1E6FFF;
		border-radius: 10rpx;
		font-size: 17px;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		text-align: center;
	}
}
</style>
